package initialize

import (
	sentinel "github.com/alibaba/sentinel-golang/api"
	"github.com/alibaba/sentinel-golang/core/flow"
	"go.uber.org/zap"
)

// 限流器
func InitSentinel() {
	// 先进行初始化
	err = sentinel.InitDefault()
	if err != nil {
		zap.S().Error(err)
	}
	//配置限流规则
	_, err = flow.LoadRules([]*flow.Rule{
		{
			Resource:               "some-test",
			TokenCalculateStrategy: flow.Direct,
			ControlBehavior:        flow.Reject,
			Threshold:              100, //qps：100/s
			StatIntervalInMs:       1000,
		},
	})
	if err != nil {
		zap.S().Error(err)
		return
	}
}
